package cn.edu.javaweb.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;

/**
 * Servlet Filter implementation class CharacterEncodingFilter
 */
@WebFilter(urlPatterns = { "/*" }, initParams = { @WebInitParam(name = "lhy", value = "utf-8") })
public class Filter209 implements Filter {

	protected FilterConfig config;
	protected String encoding;

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {

		// System.out.println(this.encoding);
		if (encoding != null) {
			request.setCharacterEncoding(this.encoding);
			response.setContentType("text/html;charset=" + this.encoding);
		}
		chain.doFilter(request, response);
	}

	@Override
	public void init(FilterConfig fConfig) throws ServletException {
		// TODO Auto-generated method stub
		config = fConfig;
		encoding = config.getInitParameter("lhy");
		// System.out.println(encoding);
	}

}
